//构造器
//方法名和类名相同
//没有返回值
//构造器是完成对象的初始化，并不是创建对象
//在创建对象时，系统会自动调用该类的构造器完成对对象的初始化
/*
public class test {
    public static void main(String[] args) {
        person p1 = new person("lihua",67);
        System.out.println(p1.name);
        System.out.println(p1.age);
        person p2 = new person("tom");

    }
}

class person{
    String name;
    int age;
    //构造器
    public person(String Pname,int Page){
        name = Pname;
        age = Page;
    }
    //构造器的重载：一个类中可以定义多个相同名字的构造器，但形参部分不能相同
    public person(String Pname){
        name = Pname;
    }

}*/

/*
public class test {
    public static void main(String[] args) {
        person p1 = new person();
        System.out.println("name=" + p1.name + " " + "age=" + p1.age);
        person p2 = new person("lihua",19);
        System.out.println("name=" + p2.name + " " + "age=" + p2.age);
    }
}
class person{
    String name;
    int age;

    //无参构造器
    public person(){
        age = 18;
    }
    //有参构造器
    public person(String pName,int pAge){
        name = pName;
        age = pAge;
    }
}*/





//this关键字
//this关键字可以用来访问本类的属性，方法，构造器
//this用于区分当前类的属性和局部变量
//访问成员方法的语法：this.方法名(参数列表)
//访问构造器的语法:this(参数列表)；注意只能在构造器中使用
//this不能在类的定义的外部使用，只能在类定义的方法中使用
/*
public class test {
    public static void main(String[] args) {
//        Dog d1 = new Dog("lihua",5);
//        d1.info();
        T t = new T();
        t.f2();
    }
}

//class Dog{
//     String name;
//     int age;
//     public Dog(String name,int age){
//         //this表示当前对象的属性name和age
//        this.name = name;
//        this.age = age;
//     }
//     public void info(){
//         System.out.println(name + " " + age);
//     }
//}
class T{
    public T(){
//访问构造器的语法:this(参数列表)；注意只能在构造器中使用,并且语句必须放在第一条
        this("jack",10);
        System.out.println("T()");
    }
    public T(String name,int age){
        System.out.println("T(String name,int age)");
    }



    public void f1(){
        System.out.println("f1()方法被调用");
    }
    public void f2(){
        System.out.println("f2()方法被调用");
        //1.直接调用
        f1();
        //2.访问成员方法的语法：this.方法名(参数列表)
        this.f1();
    }
}*/

import java.util.Random;
import java.util.Scanner;

/*public class test {
    public static void main(String[] args) {
    person p = new person("lihua",23);
    person p2 = new person("tom",23);
        System.out.println(p2.compareto(p));

    }
}

class person{
    String name;
    int age;

    public person(String name,int age){
        this.name = name;
        this.age = age;
    }

    public boolean compareto(person p){
//        if(this.name.equals(p.name) && this.age == p.age){
//            return true;
//        }
//        else{
//            return false;
//        }
        return (this.name.equals(p.name) && this.age == p.age);
    }
}*/


/*public class test {
    public static void main(String[] args) {
        String arr[] ={"jack","tom","lihua"};
        String str = "lihua";
        A02 a = new A02();
        if(a.find(str,arr) != -1){
            System.out.println(a.find(str,arr));
        }
        else{
            System.out.println("查找失败");
        }

    }
}

class A02{
    public int find(String str,String arr[]){
        for(int i = 0;i< arr.length;i++){
            if(arr[i].equals(str)){
                return i;
            }
        }
        return -1;
    }
}*/


/*public class test {
    public static void main(String[] args) {
    Book book1 = new Book("shu1",156);
    Book book2 = new Book("shu2",123);
    book1.updatePrice();
    book2.updatePrice();
    System.out.println(book1.price);
    System.out.println(book2.price);
    }
}
class Book{
    String name;
    int price;

    public Book(String name,int price){
        this.name = name;
        this.price = price;
    }

    public void updatePrice(){
        if(this.price > 150){
            price = 150;
        }
        else if(this.price >100){
            price = 100;
        }
    }
}*/

/*
public class test {
    public static void main(String[] args) {
    int oldarr[] = {1,2,3,4,5,6,7};
    A03 a = new A03();
    int newarr[] = a.copyarr(oldarr);
        for(int i = 0;i<newarr.length;i++){
            System.out.print(newarr[i] + " ");
        }

    }
}
class A03{
    public int[] copyarr(int oldarr[]){
        int newarr[] = new int[oldarr.length];
        for(int i = 0;i<oldarr.length;i++){
            newarr[i] = oldarr[i];
        }
        return newarr;
    }
}
*/

public class test {
    public static void main(String[] args) {
    circle r1 = new circle(1.2);
        System.out.println("面积=" + r1.area());
        System.out.println("周长=" + r1.len());

    }
}

class circle{
    double radius;

    public circle(double radius){
        this.radius = radius;
    }
    public double len(){
        return 2 * Math.PI * radius;
    }
    public double area(){
        return   Math.PI * radius * radius;
    }
}

